﻿/// <reference path="_namespace.js" />
/// <reference path="IComparer.js" />

/*****************************************************************************
Ajaxna library class definition. Inheriting from ajax.BaseObject.
Author: krobinson 10/8/2008 12:38:52 PM.
Class:  ajax.collections.Comparer
*****************************************************************************/

$addNamespace("ajax.collections");
//-----------------------------------------------------------------------------

ajax.collections.Comparer = function()
{///<summary>Compares two objects for equivalence, where simple string comparisons are all that are needed.
 ///Use this class as a default string comparer or inherit from it, overriding the "compare" method.</summary>
    ajax.collections.Comparer.superConstructor.call(this);
}
$extend("ajax.collections.Comparer", "ajax.BaseObject");
$supports("ajax.collections.Comparer", "ajax.collections.IComparer");
if ($getDesignMode())
    ajax.collections.Comparer.prototype = ajax.BaseObject.prototype;
//-----------------------------------------------------------------------------

// Public members
//-----------------------------------------------------------------------------


// Public Methods
//-----------------------------------------------------------------------------

// Implement IComparer
//-----------------------------------------------------------------------------
ajax.collections.Comparer.prototype.compare = function(x, y)
{///<summary>Performs a string comparison of two objects using "toString()" and
 ///     returns a value indicating whether one is less than, equal to, or greater
 ///     than the other.
 ///</summary>
 
    if (x.toString() < y.toString())
        return -1;
    else if (x.toString() > y.toString())
        return 1;
    return 0;
}

// Statics
//-----------------------------------------------------------------------------
ajax.collections.Comparer.cast = function(obj)
{///<returns type="ajax.collections.Comparer"/>
    return obj;
}